from machine import Pin,Timer
import time

class irq(object):
    def __init__(self,pin):
        self.tik=0
        self.button=Pin(pin,Pin.IN,Pin.PULL_UP)
        self.button.irq(handler=self.irq_button,trigger=Pin.IRQ_FALLING)
    def irq_button(self,pin):
        time.sleep_ms(10)
        if self.button.value()==0:
            time.sleep_ms(490)
            if self.button.value()==0:
                #长按
                print("CN")
                self.tik=2
            else:
                print("DN")
                self.tik=1
    def get(self):
        value=self.tik
        self.tik=0
        return value

def timer(df,num=0,tm=3,tm_type=1):
    t=Timer(num)
    if tm_type==1:
        t.init(period=tm*1000, mode=Timer.PERIODIC, callback=lambda x: df())
        #定时执行
    else:
        t.init(period=tm*1000, mode=Timer.ONE_SHOT, callback=lambda x: df())
        #执行一次
